package org.ipb.controller.modul.kelompokstruktur;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;

import org.ipb.model.KelompokStruktur;

import util.hibernate.DAO;

import com.opensymphony.xwork2.ActionSupport;

public class ActionStreamText extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private InputStream inputStream;

	public InputStream getInputStream() {
		return inputStream;
	}

	public String execute() {

		DAO<Integer> dao = new DAO<Integer>();
		@SuppressWarnings("unchecked")
		List<KelompokStruktur> listKelompokStruktur = (List<KelompokStruktur>) dao
				.findAll(KelompokStruktur.class);
		String streamtext = "<select id='kelompokStruktur'>";
		for (KelompokStruktur s : listKelompokStruktur) {
			streamtext += "<option value='" + s.getId() + "'>" + s.getNama()
					+ "</option>";
		}
		streamtext += "</select>";
		
		try {
			inputStream = new ByteArrayInputStream(streamtext.getBytes("UTF-8"));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		dao.close();
		return SUCCESS;
	}

}
